let api = [];
const apiDocListSize = 1
api.push({
    name: 'default',
    order: '1',
    list: []
})
api[0].list.push({
    alias: 'AnnouncementController',
    order: '1',
    link: '公告_前端控制器',
    desc: '公告 前端控制器',
    list: []
})
api[0].list[0].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/announcement/query',
    desc: '公告查询',
});
api[0].list[0].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/announcement/querybyId/{annId}',
    desc: '根据Id查询',
});
api[0].list.push({
    alias: 'ApplicantController',
    order: '2',
    link: '申请用户表_前端控制器',
    desc: '申请用户表 前端控制器',
    list: []
})
api[0].list[1].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/applicant/login',
    desc: '申请人登录接口',
});
api[0].list[1].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/applicant/register',
    desc: '申请人注册',
});
api[0].list[1].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/applicant/userinfo',
    desc: '获取用户信息',
});
api[0].list.push({
    alias: 'CaptchaController',
    order: '3',
    link: '验证码接口',
    desc: '验证码接口',
    list: []
})
api[0].list[2].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/captcha',
    desc: '图形验证码接口',
});
api[0].list.push({
    alias: 'EventsController',
    order: '4',
    link: '活动_前端控制器',
    desc: '活动 前端控制器',
    list: []
})
api[0].list[3].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/events/{id}',
    desc: '活动查询',
});
api[0].list[3].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/events/eventstopslt',
    desc: '活动列表查询',
});
api[0].list.push({
    alias: 'FileEntiyController',
    order: '5',
    link: '附件与文件表_前端控制器',
    desc: '附件与文件表 前端控制器',
    list: []
})
api[0].list[4].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/materialsUpload/{materialsid}',
    desc: '上传个人申报材料',
});
api[0].list[4].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/file/down',
    desc: '文件下载',
});
api[0].list[4].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/file/list',
    desc: '获取文件下载列表',
});
api[0].list[4].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/user/photo',
    desc: '个人照片上传',
});
api[0].list.push({
    alias: 'HdsbclController',
    order: '6',
    link: '活动申报材料_前端控制器',
    desc: '活动申报材料 前端控制器',
    list: []
})
api[0].list.push({
    alias: 'SbclController',
    order: '7',
    link: '个人申报材料_前端控制器',
    desc: '个人申报材料 前端控制器',
    list: []
})
api[0].list.push({
    alias: 'WChxhGzjlDt2Controller',
    order: '8',
    link: '工作经历_前端控制器',
    desc: '工作经历 前端控制器',
    list: []
})
api[0].list[7].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/work/workadd',
    desc: '工作经历添加',
});
api[0].list[7].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/work/workdle',
    desc: '工作经历批量或单一删除',
});
api[0].list[7].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/work/workslt',
    desc: '工作经历分页查询',
});
api[0].list.push({
    alias: 'WChxhKscjDtController',
    order: '9',
    link: '考试成绩_前端控制器',
    desc: '考试成绩 前端控制器',
    list: []
})
api[0].list[8].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/score/scoreadd',
    desc: '考试成绩',
});
api[0].list[8].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/score/scoredle',
    desc: '学习培训经历批量或单一删除',
});
api[0].list[8].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/score/scoreslt',
    desc: '学习培训经理分页查询',
});
api[0].list.push({
    alias: 'WChxhRzhgzyjdjDt4Controller',
    order: '10',
    link: '任职后业绩_前端控制器',
    desc: '任职后业绩 前端控制器',
    list: []
})
api[0].list[9].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/ofafter/ofafteradd',
    desc: '任职后工作业绩添加',
});
api[0].list[9].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/ofafter/ofafterdle',
    desc: '任职后工作业绩批量或单一删除',
});
api[0].list[9].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/ofafter/ofafterslt',
    desc: '任职后工作业绩分页查询',
});
api[0].list.push({
    alias: 'WChxhRzqgzyjdjDt3Controller',
    order: '11',
    link: '任职前工作业绩登记_前端控制器',
    desc: '任职前工作业绩登记 前端控制器',
    list: []
})
api[0].list[10].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/offront/offrontadd',
    desc: '任职前工作业绩添加',
});
api[0].list[10].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/offront/offrontdle',
    desc: '任职前工作业绩批量或单一删除',
});
api[0].list[10].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/offront/offrontslt',
    desc: '任职前工作业绩分页查询',
});
api[0].list.push({
    alias: 'WChxhXxpxjlDt1Controller',
    order: '12',
    link: '学习培训经历_前端控制器',
    desc: '学习培训经历 前端控制器',
    list: []
})
api[0].list[11].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/study/studyadd',
    desc: '学习培训经历添加',
});
api[0].list[11].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/study/studydle',
    desc: '学习培训经历批量或单一删除',
});
api[0].list[11].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/study/studyslt',
    desc: '学习培训经理分页查询',
});
api[0].list.push({
    alias: 'WChxhZscqFormController',
    order: '13',
    link: '主要知识产权证明目录_前端控制器',
    desc: '主要知识产权证明目录 前端控制器',
    list: []
})
api[0].list.push({
    alias: 'WChxhZzlwjzyjsbgdjDt5Controller',
    order: '14',
    link: '著作论文及重要技术报告登记_前端控制器',
    desc: '著作论文及重要技术报告登记 前端控制器',
    list: []
})
api[0].list[13].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/paper/paperadd',
    desc: '学习培训经历添加',
});
api[0].list[13].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/paper/paperdle',
    desc: '学习培训经历批量或单一删除',
});
api[0].list[13].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/paper/paperslt',
    desc: '学习培训经理分页查询',
});
api[0].list.push({
    alias: 'WtzxController',
    order: '15',
    link: '问题咨询_前端控制器',
    desc: '问题咨询 前端控制器',
    list: []
})
api[0].list[14].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/inquiry/all',
    desc: '查询所有问题咨询',
});
api[0].list[14].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/inquiry/add',
    desc: '新增提问内容',
});
api[0].list[14].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/inquiry/{id}',
    desc: '根据编号查询',
});
api[0].list.push({
    alias: 'ZyjszwrzzgpsController',
    order: '16',
    link: '专业技术职务任职资格评审表_前端控制器',
    desc: '专业技术职务任职资格评审表 前端控制器',
    list: []
})
api[0].list[15].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/review/add',
    desc: '添加专业资格评审表',
});
api[0].list[15].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://127.0.0.1:8085/review/query',
    desc: '查询 专业技术职务任职资格评审表',
});
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
    const theEvent = e;
    const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code == 13) {
        const search = document.getElementById('search');
        const searchValue = search.value.toLocaleLowerCase();

        let searchGroup = [];
        for (let i = 0; i < api.length; i++) {

            let apiGroup = api[i];

            let searchArr = [];
            for (let i = 0; i < apiGroup.list.length; i++) {
                let apiData = apiGroup.list[i];
                const desc = apiData.desc;
                if (desc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                    searchArr.push({
                        order: apiData.order,
                        desc: apiData.desc,
                        link: apiData.link,
                        list: apiData.list
                    });
                } else {
                    let methodList = apiData.list || [];
                    let methodListTemp = [];
                    for (let j = 0; j < methodList.length; j++) {
                        const methodData = methodList[j];
                        const methodDesc = methodData.desc;
                        if (methodDesc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                            methodListTemp.push(methodData);
                            break;
                        }
                    }
                    if (methodListTemp.length > 0) {
                        const data = {
                            order: apiData.order,
                            desc: apiData.desc,
                            link: apiData.link,
                            list: methodListTemp
                        };
                        searchArr.push(data);
                    }
                }
            }
            if (apiGroup.name.toLocaleLowerCase().indexOf(searchValue) > -1) {
                searchGroup.push({
                    name: apiGroup.name,
                    order: apiGroup.order,
                    list: searchArr
                });
                continue;
            }
            if (searchArr.length === 0) {
                continue;
            }
            searchGroup.push({
                name: apiGroup.name,
                order: apiGroup.order,
                list: searchArr
            });
        }
        let html;
        if (searchValue == '') {
            const liClass = "";
            const display = "display: none";
            html = buildAccordion(api,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        } else {
            const liClass = "open";
            const display = "display: block";
            html = buildAccordion(searchGroup,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        }
        const Accordion = function (el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;
            const links = this.el.find('.dd');
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
        };
        Accordion.prototype.dropdown = function (e) {
            const $el = e.data.el;
            $this = $(this), $next = $this.next();
            $next.slideToggle();
            $this.parent().toggleClass('open');
            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
            }
        };
        new Accordion($('#accordion'), false);
    }
}

function buildAccordion(apiGroups, liClass, display) {
    let html = "";
    let doc;
    if (apiGroups.length > 0) {
         if (apiDocListSize == 1) {
            let apiData = apiGroups[0].list;
            for (let j = 0; j < apiData.length; j++) {
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_' + apiData[j].link + '">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                html += '<ul class="sectlevel2" style="'+display+'">';
                doc = apiData[j].list;
                for (let m = 0; m < doc.length; m++) {
                    let spanString;
                    if (doc[m].deprecated == 'true') {
                        spanString='<span class="line-through">';
                    } else {
                        spanString='<span>';
                    }
                    html += '<li><a href="#_1_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                }
                html += '</ul>';
                html += '</li>';
            }
        } else {
            for (let i = 0; i < apiGroups.length; i++) {
                let apiGroup = apiGroups[i];
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_' + apiGroup.name + '">' + apiGroup.order + '.&nbsp;' + apiGroup.name + '</a>';
                html += '<ul class="sectlevel1">';

                let apiData = apiGroup.list;
                for (let j = 0; j < apiData.length; j++) {
                    html += '<li class="'+liClass+'">';
                    html += '<a class="dd" href="#_'+apiGroup.order+'_'+ apiData[j].order + '_'+ apiData[j].link + '">' +apiGroup.order+'.'+ apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                    html += '<ul class="sectlevel2" style="'+display+'">';
                    doc = apiData[j].list;
                    for (let m = 0; m < doc.length; m++) {
                       let spanString;
                       if (doc[m].deprecated == 'true') {
                           spanString='<span class="line-through">';
                       } else {
                           spanString='<span>';
                       }
                       html += '<li><a href="#_'+apiGroup.order+'_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">'+apiGroup.order+'.' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                   }
                    html += '</ul>';
                    html += '</li>';
                }

                html += '</ul>';
                html += '</li>';
            }
        }
    }
    return html;
}